<?php
namespace TPH\Model;
use Think\Model;
use Extend\Page;

class ChanPinGameModel extends Model{
	protected $connection = 'DB_MG_CHANPIN';

    protected $tableName = 'game'; 

    protected $tablePrefix = 'cms01_'; 

    const PAGESIZE_INDEX = 15;

    public function getList($cond) {

        $order = isset($cond['sort']) ? $cond['sort'] : 'game_id desc,game_cname asc';
        $page = isset($cond['page']) ? (int)$cond['page'] : 1;
        $pagesize = self::PAGESIZE_INDEX;

        $where = [];

        if($cond['game_id']){
            $where['game_id'] = $cond['game_id'];
        }
        if($cond['gamecate_id']){
            $where['game_type'] = $cond['gamecate_id'];
        }
        $total = $this->where($where)->count();

        $data = [];
        if($total){
            $currentrows = ($page-1)*$pagesize;
            $data = $this->where($where)->field('*')->order($order)->limit($currentrows, $pagesize)->select();
        }

        $Page = new Page($total, $pagesize);
        $show = $Page->show();
        return [$data, $show];
    }

    public function getIdName($ids = []) {
        $where = [];
        !empty($ids) && $where['game_id'] = ['in', $ids];
        return $this->where($where)->order('game_id desc')->getField('game_id,game_cname');
    }

    public function getGameSelect() {
        $game_list_temp_arr=$this->getIdName();
        $game_list_arr=count($game_list_temp_arr) && is_array($game_list_temp_arr)?$game_list_temp_arr:array();        
        $games = ['请选择'] + $game_list_arr;
        return $games;
    }
    public function getGameOptions($pfmid = '') {
        //取游戏搜索框
        $tmp = array(""=>"所有");
        if ($pfmid == '')
            $where['pfm_id']=$_SESSION['pfm_id'];
        else
            $where['pfm_id']=$pfmid;

		$game = D('game')->where($where)->select();
		foreach ($game as $k=>$v){
            // if ($v['pfm_id'] != session('pfm_id')) {
            //     $tmp[$v['game_id']] = $v['game_cname'] . '(手游)';
            // } else {
                $tmp[$v['game_id']] = $v['game_cname'];
            // }
		}

        return $tmp;
    }
    public function getCertainGameOptions($pfmid = '') {
        //取游戏搜索框
		$tmp = array("-1"=>"---请选择---");
        if ($pfmid == '')
            $where['pfm_id']=$_SESSION['pfm_id'];
        else
            $where['pfm_id']=$pfmid;

		$game = D('game')->where($where)->select();
		foreach ($game as $k=>$v){
            // if ($v['pfm_id'] != session('pfm_id')) {
            //     $tmp[$v['game_id']] = $v['game_cname'] . '(手游)';
            // } else {
                $tmp[$v['game_id']] = $v['game_cname'];
            // }
		}

        return $tmp;
    }
    public function getAllGameOptions() {
        //取游戏搜索框
        $tmp = array(""=>"所有");
		$game = D('game')->where($where)->select();
		foreach ($game as $k=>$v){
            // if ($v['pfm_id'] != session('pfm_id')) {
            //     $tmp[$v['game_id']] = $v['game_cname'] . '(手游)';
            // } else {
                $tmp[$v['game_id']] = $v['game_cname'];
            // }
		}

        return $tmp;
    }
    public function getPfmAndGameOptions($pfmid = '') {
        //取游戏搜索框
		$tmp = array("-2"=>"===全部游戏===");
        $tmp["-1"] = "===H5全平台===";
	//	$tmp = array("-1"=>"===H5全平台===");
        if ($pfmid == '')
            $where['pfm_id']=$_SESSION['pfm_id'];
        else
            $where['pfm_id']=$pfmid;

		$game = D('game')->where($where)->select();
		foreach ($game as $k=>$v){
            // if ($v['pfm_id'] != session('pfm_id')) {
            //     $tmp[$v['game_id']] = $v['game_cname'] . '(手游)';
            // } else {
                $tmp[$v['game_id']] = $v['game_cname'];
            // }
		}

        return $tmp;
    }
}
